<?php
class member_controller_admin_index extends AdminController {
	private $m;
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->m = Model::factory('member_model_data');
	}
		
	/**
	 * 用户列表
	 *
	 */
	public function user_list_action(){
		$page = _('page',1);
		$pageSize = 30;
		$args['uid'] = _('uid');
		$args['username']	=	_('username');
		$args['email']	=	_('email');
		$args['sex']	=	_('sex');
		
		$list = $this->m->search($args,$page,20);
		$pages = $this->genPages($list['INFO'],$args);
		
		$this->ret = array('data'=>$list['ROWS'],'pages'=>$pages);
	}
	
	/**
	 * 删除用户
	 *
	 */
	public function remove_action(){
		$uid = _('uid');
		$this->_renderJson();
		if($rs = Model::factory('admin_model_user')->remove($uid)){
			$this->ret = self::success();
		}else{
			$this->ret = self::failure("删除失败");
		}
	}
	
	/**
	 * 设置用户状态
	 *
	 */
	public function set_flag_action(){
		$uid = _('uid');
		$flag = _('flag');
		$this->_renderJson();		
		if($this->m->setUserFlag($uid,$flag)){
			$this->ret = self::success();
		}else $this->ret = self::failure('设置失败');
	}
	
	/**
	 * 关闭用户
	 *
	 */
	public function close_action(){
		$uid = _('uid');
		$this->_renderJson();
		if($this->m->setUserFlag($uid,FLAG_SHIELDING)){
			$this->ret = self::success();
		}else $this->ret = self::failure('关闭用户失败');
	}
	
	/**
	 * 搜索用户
	 *
	 */
	/*public function search_action(){
		$prop = Model::factory('index_model_standardprop');
		$data = $prop->adminSearch($this->uid, $this->username, $this->gender, $this->page, 30);
		$this->ret = self::success($data);
	}*/
	
	public function profile_action(){
		$this->type = _('type', 'default');
		$prop = Model::factory('index_model_standardprop');
		$online = Model::factory('index_model_online');
		
		$this->ret = self::success(array_merge($prop->select($this->uid), $online->select($this->uid)));
		
	}
	
	/**
	 * 关闭用户
	 *
	 */
	/*public function close_action()
	{
		$uid = (int) $_POST['uid'];
		$prop = Model::factory('index_model_standardprop');
		if ($prop->edit(array('status' => -1), $uid)) {
			if ($userInfo = friends_util_cache::getUserInfo($uid)) {
				$userInfo['status'] = -1;
				MemRow::setCache(MemRow::genRowKey('friends', $uid), $userInfo);
			}
		}
		
		header('Location: ' . AdminController::_makeURL('account', 'index', 'index'));
	}*/
	
	/**
	 * 开启用户
	 *
	 */
	public function open_action()
	{
		$uid = (int) $_GET['uid'];
		$prop = Model::factory('index_model_standardprop');
		if ($prop->edit(array('status' => 0), $uid)) {
			if ($userInfo = friends_util_cache::getUserInfo($uid)) {
				$userInfo['status'] = 0;
				MemRow::setCache(MemRow::genRowKey('friends', $uid), $userInfo);
			}
		}
		
		header('Location: ' . AdminController::_makeURL('account', 'index', 'index'));
	}
}